﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.DAL;
using System.Collections.Generic;
using System;

namespace Inventory.Test
{   
    /// <summary>
    ///This is a test class for PhysicalInventoryTransactionTest and is intended
    ///to contain all PhysicalInventoryTransactionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PhysicalInventoryTransactionTest
    {
        PhysicalInventoryTransaction transaction = new PhysicalInventoryTransaction();

    

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            var result = transaction.GetById(31);

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Items.Count);
            Assert.AreEqual(3, result.Items.Count);
        }

        /// <summary>
        ///A test for Edit
        ///</summary>
        [TestMethod()]
        public void EditTest()
        {
            var phInv = transaction.GetById(31);

            //phInv.Code += "!";
            //phInv.Items.RemoveAt(phInv.Items.FindIndex(i => i.ID == 19101));
            phInv.Items.Find(i => i.Id == 19100).Quantity = 600;

            Assert.IsTrue(transaction.Edit(phInv));
        }

        /// <summary>
        ///A test for Create
        ///</summary>
        [TestMethod()]
        public void CreateTest()
        {
            var phInv = new Business.DomainObjects.PhysicalInventory()
            {
                CreationDate = DateTime.Now,
                Status = Inventory.Business.DomainObjects.TransactionStatus.Open,
                Warehouse = 4
            };
            phInv.Items.Add(new Inventory.Business.DomainObjects.PIMaterialItem()
            {
                Id = 19102,
                Area = Inventory.Business.DomainObjects.Area.Inspection,
                Expected = 0,
                Quantity = 7
            });

            phInv.Items.Add(new Inventory.Business.DomainObjects.PIMaterialItem()
            {
                Id = 19101,
                Area = Inventory.Business.DomainObjects.Area.Inventory,
                Expected = 1,
                Quantity = 107
            });

            phInv.Items.Add(new Inventory.Business.DomainObjects.PIMaterialItem()
            {
                Id = 19100,
                Area = Inventory.Business.DomainObjects.Area.OnSite,
                Expected = 1,
                Quantity = 5
            });

            Assert.IsTrue(transaction.Create(phInv));
        }

        /// <summary>
        ///A test for Commit
        ///</summary>
        [TestMethod()]
        public void CommitTest()
        {
            var PInv = transaction.GetById(31);
            Assert.IsTrue(transaction.Commit(PInv));
        }
    }
}
